cmake_minimum_required(VERSION 3.16)
project(word_list_core)

set(CMAKE_CXX_STANDARD 14)


include(FetchContent)
FetchContent_Declare(
        googletest
        URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

enable_testing()
set(src_list
        src/api.cpp
        src/Graph.cpp
        src/utils/utils.cpp
        src/utils/errors.cpp
        src/exceptions/WordListException.cpp)
set(header_list
        src/api.h
        src/Graph.h
        src/utils/utils.h
        src/utils/errors.h
        src/exceptions/WordListException.h
        src/common.h)

add_library(core SHARED
        ${header_list}
        ${src_list})
add_library(static_core
        ${header_list}
        ${src_list})
add_executable(
        Wordlist
        src/main.cpp
        src/OptionParser.cpp
        src/OptionParser.h
        src/cli.h
        src/cli.cpp
        ${header_list})
target_link_libraries(Wordlist core)

add_executable(tests test/test.cpp test/test.h src/OptionParser.cpp
        src/OptionParser.h ${header_list} ${src_list} src/cli.h
        src/cli.cpp)
add_executable(basic_test
        test/test_utils.cpp
        ${header_list}
        ${src_list})
add_executable(cli_tests test/cli_test.cpp src/OptionParser.cpp src/OptionParser.h ${header_list} ${src_list})
add_executable(api_tests test/api_test.cpp ${header_list})
target_link_libraries(
        tests
        GTest::gtest_main
        GTest::gmock
)

target_link_libraries(
        basic_test
        GTest::gtest_main
        GTest::gmock
)

target_link_libraries(
        cli_tests
        GTest::gtest_main
        GTest::gmock
)
target_link_libraries(
        api_tests
        core
        GTest::gtest_main
        GTest::gmock
)

include(GoogleTest)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
    SET_TARGET_PROPERTIES(Wordlist PROPERTIES LINK_FLAGS "/PROFILE") # for vs perf
    SET_TARGET_PROPERTIES( PROPERTIES LINK_FLAGS "/PROFILE") # for vs perf
endif ()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
    add_custom_command(
            TARGET
            tests
            POST_BUILD
            COMMAND
            OpenCppCoverage.exe ${CMAKE_CURRENT_BINARY_DIR}/tests.exe --working_dir ${CMAKE_CURRENT_SOURCE_DIR}\\.. --sources word_list_core\\src\\* --optimized_build
            COMMENT
            "coverage"
            VERBATIM
    )
endif ()

FIND_PACKAGE(OpenMP REQUIRED)
if (OPENMP_FOUND)
    message("OPENMP FOUND")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif ()
